package com.itheima.zuoye2.zuoye2;

import java.util.Arrays;
import java.util.Comparator;

public class Test {
    public static void main(String[] args) {
//        定义数组
        Student[] students = new Student[5];
        students[0] = new Student("张三",20,"男","1.80",88.5);
        students[1] = new Student("李四",19,"女","1.70",92.0);
        students[2] = new Student("王五",21,"男","1.60",85.5);
        students[3] = new Student("赵六",20,"女","1.50",90.5);
        students[4] = new Student("孙七",21,"男","1.40",100);
        //按年纪排序 arrsort如果年龄一样按成绩划分
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result = o1.getAge() - o2.getAge();
                if (result == 0) {
                    result = Double.compare(o1.getScore(), o2.getScore());
                }
                return result;
            }
        });

        for (Student student : students) {
            System.out.println(student);
        }

    }
}
